package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) {
        String name;
        String nickName;
        int age;
        String passWord;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        name=sc.nextLine();
        System.out.println("请输入小名:");
        nickName = sc.nextLine();
        System.out.println("请输入密码:");
        passWord = sc.nextLine();
        System.out.println("请输入年龄:");
        age = sc.nextInt();
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql="insert into user (username,nickname,age,password) values('"+name+"','"
                    +nickName+"',"+age+",'"+passWord+"')";
            int num=statement.executeUpdate(sql);
            System.out.println(num>0?"删除成功":"删除失败");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
